package vfs.filter.impl;

import vfs.filter.VFSAttributeConstraint;
import vfs.filter.VFSFilter.VFSFilterOperator;

/**
 * The VFSAttributeConstraint class represents a constraint on
 * a particular object's attribute when filtering objects.  A
 * collection of these constraints are contained within a VFSFilter.
 * 
 * @author Matthew Eavenson <durandal@uga.edu>
 */
public class VFSAttributeConstraintImpl implements VFSAttributeConstraint {
    
    private String attribute;
    private VFSFilterOperator op;
    private String value;
    private String value2;
    
    public VFSAttributeConstraintImpl(String attribute){
        this.attribute = attribute;
        op = VFSFilterOperator.EQ;
        value = null;
        value2 = null;
    }
    
    /**
     * Returns the attribute that this constraint is meant to
     * apply to.  There are currently no guarantees that the
     * attribute will be a valid attribute over a particular
     * object.
     * 
     * @return the attribute that this constraint applies to
     */
    @Override
    public String getAttribute() {
        return attribute;
    }

    /**
     * Assigns an operator to this constraint, where the
     * operator is one of the enum VFSFilterOperator.
     * 
     * @param op operator that this constraint will apply
     */
    @Override
    public void setOperator(VFSFilterOperator op) {
        this.op = op;
    }

    /**
     * Returns the operator that this constraint will apply
     * when used in a filter.
     * 
     * @return the operator that this constraint applies
     */
    @Override
    public VFSFilterOperator getOperator() {
        return op;
    }

    /**
     * Assigns a value for the constraint to test the attribute 
     * against.  Even if the value is numerical, it should still 
     * be entered in String form.
     * 
     * @param value the value that this constraint will test against
     */
    @Override
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * Returns the value that this constraint will test the
     * object's attribute against.
     * 
     * @return the value that this constraint will test against
     */
    @Override
    public String getValue() {
        return value;
    }

    /**
     * Sets an optional second value for range queries.
     * 
     * @param value the optional range value
     */
    @Override
    public void setRangeValue(String value) {
        value2 = value;
    }

    /**
     * Returns an optional second value for range queries.
     * 
     * @return the value that this constraint will test against
     */
    @Override
    public String getRangeValue() {
        return value2;
    }
    
}
